package com.hmall.order.web;

import com.hmall.order.pojo.Order;
import com.hmall.order.service.impl.OrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * The type Pay controller.
 */
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/pay")
@RestController
public class PayController {

    private final OrderService orderService;

    /**
     * 查询订单状态
     *
     * @param id the id
     * @return the integer
     */
    @GetMapping("status/{id}")
    public Integer status(@PathVariable Long id) {
        Order order = orderService.getById(id);
        if (order.getStatus() == 1) {
            return 1;
        }
        return 2;
    }


    /**
     * 改变订单状态
     *
     * @return the order
     */
    @GetMapping("/url/{tab}/{id}")
    public Order pay(@PathVariable Long id, @PathVariable String tab) {
        Order order = Order.builder()
                .id(id)
                .status(2)
                .build();
        orderService.updateById(order);
        return orderService.getById(id);
    }

}